home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / dfa13.zip / DFA13.ASM < prev    next >
Assembly Source File  |  1986-11-20  |  19KB  |  797 lines

  1.  
  2.    title  DFA13 - DOS File Accelerator version 1.3
  3.    page 60,132
  4.  
  5. ;
  6. ; DFA13 - DOS File Accelerator v1.3        20-Nov-86, S.H.Smith
  7. ;
  8. ; DFA is a small resident utility that can "accelerate" file access
  9. ; in many programs.
  10. ;
  11. ; DFA predicts when your program will want to read from a file and
  12. ; reads the data into a buffer before it is asked for.  This is the
  13. ; opposite of a "cache" type program.  A cache keeps data AFTER it has
  14. ; been used; DFA gets data BEFORE it is needed.
  15. ;
  16. ; WARNING: This program goes between your programs and DOS and had
  17. ; the potential of causing data loss.  Make sure you have made a backup
  18. ; before you try this program.
  19. ;
  20. ; Written by Samuel H. Smith, 24-may-86
  21. ; Assemble with MASM v4.0
  22. ;
  23.  
  24.  
  25. ;----------------------------------------
  26. ;
  27.   public bufsize,maxread,status,readhits,realreads,handle,bytesinbuf
  28.   public position,seek_hi,seek_lo,bytesread,oldintvec,retip
  29.   public nametabl,namechg
  30.  
  31. code segment
  32.    assume cs:code,ds:nothing,es:nothing,ss:nothing
  33.    org 100h
  34.  
  35. entry:
  36.    jmp startup
  37.  
  38.  
  39. ;----------------------------------------
  40. ; program configuration and statistics (these should not be moved)
  41. ;
  42. bufsize    dw 4000h     ;size of the file buffer.
  43.                         ;can be up to 0FC00H.
  44.  
  45. maxread    dw 1000h     ;largest data read size that will enable
  46.                         ;buffering on a file.
  47.                         ;larger initial reads will not be buffered.
  48.  
  49. readhits   dw 0         ;count of reads that were satisfied by the buffer
  50.  
  51. realreads  dw 0         ;count of real reads done through dos on buffered files
  52.  
  53. bytesinbuf dw 0         ;number of bytes currently in the buffer
  54.  
  55. namechg    db 0         ;flags that one of the captured filenames has changed
  56.  
  57. ;space for the filenames for each of the 20 handles
  58. nametabl   db 1280 dup (0)
  59.  
  60. ; a binary signature hex 'DFAC' used to tell if DFA is already present
  61. binsig     dw 0DFACh
  62.  
  63.  
  64.  
  65. ;----------------------------------------
  66. ; file status variables
  67. ;
  68.  
  69. status     db 0         ;acceleration status
  70.        ready = 0           ;ready to accelerate
  71.        recursion = 088h    ;using interrupt recursion
  72.        disabled = 0ffh     ;disabled
  73.  
  74. nohandle   equ word ptr 03333h
  75.                         ;special handle value when there is no current handle
  76.  
  77. handle     dw nohandle  ;the file handle for the current file
  78.  
  79. position   dw 0         ;the next read position of the current file
  80.                         ;from the local buffer
  81.  
  82. seek_hi    dw 0         ;32 bit base position for current file
  83. seek_lo    dw 0
  84.  
  85. bytesread  dw 0         ;number of bytes read in current readfrombuf call
  86.  
  87. openmode   dw 0         ;open access code for last open/creat
  88. nameseg    dw 0
  89. nameofs    dw 0
  90.  
  91.  
  92. ; a signature in bytes ($ terminated)
  93. signature  db 13,10,'DOS File Accelerator v1.3 (SHS, 20-Nov-86)'
  94.            db 13,10,'Public domain material.  Personal use only.'
  95.            db 13,10,'$'
  96.            db 13,10,'by Samuel H. Smith',
  97.            db 13,10,'   5119 N. 11th Ave 332'
  98.            db 13,10,'   Phoenix, Az 85013'
  99.            db 13,10
  100.            db 1ah
  101.  
  102.  
  103.  
  104.  
  105. ;----------------------------------------
  106. ; working storage
  107. ;
  108.  
  109. ; vector for old interrupt
  110. oldintvec  dd 0
  111.  
  112. ; user return data
  113. retip     dd 0
  114.  
  115. retflag   dw 0
  116. localip   dw 0
  117.  
  118.  
  119. ;----------------------------------------
  120. ; macros
  121. ;
  122. jbz macro lab
  123.    jb lab
  124.    jz lab
  125.    endm
  126.  
  127. jahz macro val,lab
  128.    cmp ah,val
  129.    jz lab
  130.    endm
  131.  
  132. display macro text
  133.    push ds
  134.    push cs
  135.    pop ds
  136.    mov dx,offset text
  137.    mov ah,9
  138.    int 21h
  139.    pop ds
  140.    endm
  141.  
  142.  
  143. ;========================================
  144. ; new interrupt service
  145. ;----------------------------------------
  146. newint:
  147.    public newint
  148.  
  149.    cmp status,disabled ;is DFA disabled?
  150.    jz useold
  151.  
  152.    jahz 00h,doreset          ;terminate program?
  153.    jahz 31h,doreset          ;keep process?
  154.    jahz 4bh,doreset          ;exec?
  155.    jahz 4ch,doreset          ;terminate?
  156.  
  157.    cmp status,ready   ;are we already in an interrupt?
  158.    jnz useold
  159.  
  160.    jahz 3ch,doopen           ;create function?
  161.    jahz 3dh,doopen           ;open function?
  162.    jahz 3eh,doclose          ;close function?
  163.    jahz 3fh,doread           ;read function?
  164.    jahz 40h,dowrite          ;write function?
  165.  
  166.    cmp ah,42h                ;lseek function?
  167.    jnz useold
  168.    jmp doseek
  169.  
  170.  
  171. ;----------------------------------------
  172. ; use old interrupt handler
  173. ;----------------------------------------
  174.  
  175. useold:
  176.    public useold
  177.    jmp oldintvec         ;jump to the real DOS handler
  178.  
  179.  
  180.    page
  181. ;----------------------------------------
  182. ; doreset - process DOS functions that reset all files
  183. ;----------------------------------------
  184.  
  185. doreset proc near
  186.    public doreset
  187.  
  188.    cmp handle,nohandle
  189.    jz resetx                 ;use old handler if no current file
  190.  
  191.    call setfilepos           ;set file position and let dos take over
  192.  
  193. resetx:
  194.    mov status,ready          ;clear recursion flag because sometimes
  195.                              ;dos never returns (as with ctrl-break)
  196.  
  197.    jmp useold                ;let dos do it's work
  198.  
  199. doreset endp
  200.  
  201.  
  202. ;----------------------------------------
  203. ; doopen - process DOS open function
  204. ;----------------------------------------
  205.  
  206. doopen proc near
  207.    public doopen
  208.  
  209.    mov openmode,ax
  210.    mov nameseg,ds
  211.    mov nameofs,dx
  212.  
  213.    call calldos              ;let DOS open the file
  214.  
  215.    pushf
  216.    jc openex
  217.  
  218.    call grabname             ;grab and keep the filename
  219.  
  220.    cmp handle,ax             ;if its not the current file handle
  221.    jnz openex                ;then there's nothing more to do
  222.  
  223.    mov handle,nohandle       ;we just re-opened the current file -
  224.                              ;reset handle to purge previous buffering
  225. openex:
  226.    popf
  227.  
  228.    jmp return
  229.  
  230. doopen endp
  231.  
  232.  
  233. ;----------------------------------------
  234. ; dowrite - process DOS functions that close or modify files
  235. ;----------------------------------------
  236.  
  237. dowrite proc near
  238.    public dowrite
  239.  
  240.    cmp bx,handle
  241.    jnz writex                ;use old handler if no current file
  242.  
  243.    call setfilepos           ;set file position and let dos take over
  244.  
  245. writex:
  246.    jmp useold                ;and let dos do it's work
  247.  
  248. dowrite endp
  249.  
  250.  
  251. ;----------------------------------------
  252. ; doclose - process DOS functions that close or modify files
  253. ;----------------------------------------
  254.  
  255. doclose proc near
  256.    public doclose
  257.  
  258.    call dropfile
  259.  
  260.    cmp bx,handle
  261.    jnz closex                ;use old handler if no current file
  262.  
  263.    call setfilepos           ;set file position and let dos take over
  264.  
  265. closex:
  266.    jmp useold                ;and let dos do it's work
  267.  
  268. doclose endp
  269.  
  270.  
  271.  
  272.    page
  273. ;----------------------------------------
  274. ; doread - process DOS read function
  275. ;
  276. ; This procedure is the heart of the program.  It will decide if
  277. ; read requests should be buffered or processed by DOS.
  278. ; It switches buffering to a new file when needed.
  279. ;----------------------------------------
  280.  
  281. doread proc near
  282.    public doread
  283.  
  284.    cmp bx,handle             ;is this the current file?
  285.    jz readagain              ;then read from it again
  286.  
  287.    cmp cx,maxread            ;is this read for a fairly small buffer?
  288.    jb readswitch             ;switch buffering to this file if it is
  289.  
  290.    inc realreads             ;count this as a "real" read through dos
  291.    inc readhits              ;count this as a "logical" read through dos
  292.    jmp useold                ;just let DOS do the read
  293.                              ;and keep the current file
  294.  
  295. ;
  296. ; time to switch buffering to a different file
  297. ;
  298. readswitch:
  299.    public readswitch
  300.  
  301.    cmp handle,nohandle       ;is there a current file?
  302.    jz newfile                ;open new file if not
  303.  
  304. ; unbuffer the current file
  305.    call setfilepos           ;there is a current file - reset it to it's
  306.                              ;current position so DOS can take over on later
  307.                              ;read requests.
  308.  
  309. ;
  310. ; start buffering a new file
  311. ;
  312. newfile:
  313.    public newfile
  314.  
  315.    mov namechg,1
  316.    mov handle,bx             ;make this the new cur